package com.GlobalPaint.app.Adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.GlobalPaint.app.R;
import com.GlobalPaint.app.bean.TalentBean;
import com.GlobalPaint.app.ui.Home.talent.TalentActivity;
import com.GlobalPaint.app.ui.Mine.ResumeActivity;
import com.jcodecraeer.xrecyclerview.XRecyclerView;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/12/27 0027.
 */

public class TalentAdapter extends XRecyclerView.Adapter<TalentAdapter.ViewHoler>  {
    private List<TalentBean.DataBean> list;
    private Context context;
    public TalentAdapter(List<TalentBean.DataBean> list, TalentActivity talentActivity) {
        this.list=list;
        context=talentActivity;
    }

    @Override
    public TalentAdapter.ViewHoler onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.activity_talent_item, parent, false);
        TalentAdapter.ViewHoler holder = new TalentAdapter.ViewHoler(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(TalentAdapter.ViewHoler holder, final int position) {


        if(list.size()>0) {
            String name = list.get(position).getFName() ==
                    null ? "" : list.get(position).getFName();
            String sj = list.get(position).getFCreationDate() ==
                    null ? "" : list.get(position).getFCreationDate();
            String post = list.get(position).getFPost() ==
                    null ? "" : list.get(position).getFPost();
            String phone = list.get(position).getFMobile() ==
                    null ? "" : list.get(position).getFMobile();
            if(phone.length()>4){
                String phone1=(phone.substring(0,3));
                String phone2=phone.substring(phone.length()-3,phone.length());
                holder.tv_phone.setText(phone1+"***"+phone2);
            }
            holder.tv_name.setText(name);
            if(sj.length()>10){
                holder.tv_sj.setText(sj.substring(0,10));
            }
            holder.tv_post.setText(post);

        }
        holder.mview.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ArrayList<String> info = new ArrayList<String>();
                info.add(list.get(position).getFName());
                info.add(list.get(position).getFGender());
                info.add(list.get(position).getFEducationExperience());
                info.add(list.get(position).getFMobile());
                info.add(list.get(position).getFEmail());
                info.add(list.get(position).getFBirthDate());
                info.add(list.get(position).getFPost());
                info.add(list.get(position).getFExpectedSalary());
                info.add(list.get(position).getFWorkExperience());
                info.add(list.get(position).getFRemark());
                Intent intent =new Intent(view.getContext(), ResumeActivity.class);
                intent.putExtra("activity","talent");
                intent.putExtra("infoList",info);
                view.getContext().startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public class ViewHoler extends RecyclerView.ViewHolder {
        private final TextView tv_name;
        private final TextView tv_post;
        private final TextView tv_phone;
        private final TextView tv_sj;
        View mview;

        public ViewHoler(View itemView) {
            super(itemView);
            mview = itemView;
            tv_name = (TextView)itemView.findViewById(R.id.tv_name);
            tv_post = (TextView)itemView.findViewById(R.id.tv_post);
            tv_phone = (TextView)itemView. findViewById(R.id.tv_phone);
            tv_sj = (TextView) itemView.findViewById(R.id.tv_sj);
        }
    }
}
